package com.highglass.videoplayer.db;

import android.content.Context;

import com.lidroid.xutils.db.sqlite.Selector;
import com.lidroid.xutils.db.sqlite.WhereBuilder;
import com.lidroid.xutils.exception.DbException;

import java.util.List;

public class HistoryBeanInfoDao
        extends BaseDao {
    private static HistoryBeanInfoDao dao;

    public HistoryBeanInfoDao(Context paramContext) {
        super(paramContext);
    }

    public static HistoryBeanInfoDao getinstance(Context paramContext) {
        if (dao == null) {
            dao = new HistoryBeanInfoDao(paramContext);
        }
        return dao;
    }

    public boolean delete(HistoryBean paramHistoryBean)
            throws DbException {
        this.dbUtils.delete(HistoryBean.class, WhereBuilder.b("path", "=", paramHistoryBean.path));
        return true;
    }

    public boolean deleteAll()
            throws DbException {
        this.dbUtils.deleteAll(HistoryBean.class);
        return true;
    }

    public HistoryBean find()
            throws DbException {
        this.dbUtils.createTableIfNotExist(HistoryBean.class);
        return (HistoryBean) this.dbUtils.findFirst(HistoryBean.class);
    }

    public List<HistoryBean> find10()
            throws DbException {
        this.dbUtils.createTableIfNotExist(HistoryBean.class);
        return this.dbUtils.findAll(Selector.from(HistoryBean.class).orderBy("inTime", true).limit(4));
    }

    public List<HistoryBean> findAll()
            throws DbException {
        this.dbUtils.createTableIfNotExist(HistoryBean.class);
        return this.dbUtils.findAll(HistoryBean.class);
    }

    public void insertToDB(HistoryBean paramHistoryBean)
            throws DbException {
        this.dbUtils.saveBindingId(paramHistoryBean);
    }

    public void insertToDB(List<HistoryBean> paramList)
            throws DbException {
        this.dbUtils.saveAll(paramList);
    }

    public boolean isExist(String paramString)
            throws DbException {
        this.dbUtils.createTableIfNotExist(HistoryBean.class);
        return this.dbUtils.findFirst(Selector.from(HistoryBean.class).where("path", "=", paramString)) != null;
    }
    public HistoryBean find(String paramString)
            throws DbException {
        this.dbUtils.createTableIfNotExist(HistoryBean.class);
        return this.dbUtils.findFirst(Selector.from(HistoryBean.class).where("path", "=", paramString));
    }
}